<template>
  <!--        精选文章-->
  <div id="FeaturedArticles">
    <div class="head">
      <h2>精选文章</h2>
    </div>
    <div class="body">
      <ul>
        <li v-for="(item,index) in ArticleRecommend" :key="item.nid">
          <div class="FeaturedArticles-body" @click="toarticle(item.nid)">
            <div class="body-left">
              <img alt=""
                   :src="'api'+item.cover_url">
            </div>
            <div class="body-right">
              <h2>{{ item.title }}</h2>
              <p>{{ item.abstract }}</p>
              <span>{{ item.create_date }}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import {mapActions, mapState} from 'vuex'

export default {
  name: "FeaturedArticles",
  methods: {
    // 跳转到文章详情页
    toarticle(id) {
      this.$router.push({
        name: 'article',
        params: {
          id
        }
      })
    },
    ...mapActions('Home', ['getArticleRecommend'])
  },
  mounted() {
    this.getArticleRecommend()
  },
  computed: {
    ...mapState('Home', ['ArticleRecommend'])
  }
}
</script>

<style scoped lang="less">
/*精选文章区域*/
#FeaturedArticles {
  margin-bottom: 20px;
  background-color: #ffffff;
  min-height: 200px;
  width: 100%;
  height: 430px;

  .head {
    height: 45px;
    padding: 15px 20px 15px 20px;
    justify-content: space-between;
  }

  .body {

    ul {
      display: flex;
      flex-wrap: wrap;

      li {
        height: 100px;
        width: 50%;
        padding-bottom: 20px;

        .FeaturedArticles-body {
          height: 100%;
          width: 100%;
          display: flex;
          flex-direction: row;
          float: left;

          .body-left {
            float: left;
            height: 100%;
            width: 40%;
            padding-left: 10px;

            img {
              height: 100%;
              width: 100%;
            }
          }

          .body-right {
            height: 100px;
            width: 50%;
            padding: 10px 0 10px 10px;
            line-height: 35px;
            margin-left: 10px;

            h2 {
              font-size: 18px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }

            p {
              white-space: nowrap; /* 文本不换行 */
              overflow: hidden;
              text-overflow: ellipsis;
              height: 30px;
            }
          }
        }
      }
    }


  }
}
</style>